package com.xquant.common.core.exception;

import com.xquant.common.core.domain.ErrMsg;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 业务异常
 *
 * @author xquant
 */
public final class ServiceException extends RuntimeException
{
    private static final long serialVersionUID = 1L;

    /**
     * 错误码
     */
    private Integer code;

    /**
     * 错误提示
     */
    private String message;


    protected final Logger logger = LoggerFactory.getLogger(this.getClass());
    /**
     * 空构造方法，避免反序列化问题
     */
    public ServiceException()
    {
    }

    public ServiceException(String message)
    {
        this.message = message;
        logger.error("错误信息：{0}", message);
    }

    public ServiceException(String message, Integer code)
    {
        this.message = message;
        this.code = code;
        logger.error("错误码：{0}，错误信息：{1}",code, message);
    }


    public ServiceException(ErrMsg errMsg)
    {
        this.message = errMsg.getErrMsg();
        this.code = errMsg.getErrCode();
        logger.error("错误码：{0}，错误信息：{1}",code, message);
    }
    public ServiceException(ErrMsg errMsg,String strackMsg)
    {
        this.message = errMsg.getErrMsg()+" "+strackMsg;
        this.code = errMsg.getErrCode();
        logger.error("错误码：{0}，错误信息：{1}",code, message);
    }

    public String getMessage()
    {
        return message;
    }

    public Integer getCode()
    {
        return code;
    }

    public ServiceException setMessage(String message)
    {
        this.message = message;
        return this;
    }


}
